package com.teufandsub.socialproximity.gui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.teufandsub.socialproximity.R;
import com.teufandsub.socialproximity.services.BackgroundService;

/**
 * @author Bastien Mathias <bastienmathias@gmail.com>
 * @author Antoine Teuf <antoine.teuf@gmail.com>
 * @version 1.0
 * @since 2013-05-22
 * 
 * The class to close the application
 */

public class CloseActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//Dialog to ask if you want to close the application.
		AlertDialog.Builder alertDialogBuilder =  new AlertDialog.Builder(this);
		
		alertDialogBuilder
		.setMessage(getResources().getString(R.string.alertdialog_text))
		.setTitle(getResources().getString(R.string.alertdialog_title))
		.setCancelable(false)
		.setPositiveButton(getResources().getString(R.string.alertdialog_yes),new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog,int id) {
				
				Intent intent = new Intent(CloseActivity.this, IndexActivity.class);
				startActivity(intent);		
				stopService(new Intent(CloseActivity.this, BackgroundService.class));
				moveTaskToBack(true);			
			}
		  })
		.setNegativeButton(getResources().getString(R.string.alertdialog_no),new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog,int id) {
				dialog.cancel();
				CloseActivity.this.finish();
			}
		});
		
		AlertDialog alert = alertDialogBuilder.create();
		alert.show();
	}
}
